<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

use Illuminate\Support\Facades\Auth;

use Illuminate\Support\Facades\DB;

class AdController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth:admin');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //查询AD广告价格
        $ad_price = DB::table('ad_price')
            ->select('id', 'yellow', 'all_day_yellow', 'overnight', 'fixed_overnight', 'all_day_boutique')
            ->first();

        return view('admin.ad.create',['ad_price' => $ad_price]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {

        //验证表单
        $this->validate($request, [
            'yellow' => ['required','numeric'],
            'all_day_yellow' => ['required','numeric'],
            'overnight' => ['required','numeric'],
            'fixed_overnight' => ['required','numeric'],
            'all_day_boutique' => ['required','numeric'],
        ]);

        //更新购买成功到数据库
        DB::table('ad_price')
            ->update([
                'yellow' => $request->yellow,
                'all_day_yellow' => $request->all_day_yellow,
                'overnight' => $request->overnight,
                'fixed_overnight' => $request->fixed_overnight,
                'all_day_boutique' => $request->all_day_boutique,
            ]);

        return response()->json(['message' => '编辑成功。', 'success' => 'true']);

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
